home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000115_icon-group-sender _Thu May 5 13:47:56 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
10KB
Received: by cheltenham.cs.arizona.edu; Thu, 5 May 1994 12:24:29 MST
Date: Thu, 05 May 1994 13:47:56 -0600 (CST)
From: Chris Tenaglia - 257-8765 <TENAGLIA@MIS.MCW.EDU>
Subject: Bueno Cinco de Mayo
To: icon-group@cs.arizona.edu
Message-Id: <01HBZCVUT89U8WWD9C@mis.mcw.edu>
Organization: Medical College of Wisconsin (Milwaukee, WI)
X-Vms-To: IN%"icon-group@cs.arizona.edu"
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-Transfer-Encoding: 7BIT
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
For the Cinco de Mayo I'd like to offer a little Icon code segment.
This one was developed for unix (namely ultrix 4.3 rev 44). Maybe
it will work on some other unix too. I'd like to know. This program
is called 'when'. It's like a date based ls command. Some have told
me 'find' can do the same things, but I find find a bit arcane?
So 'when' is what I use. Here are some samples :
Csh% when before 4/12/92 files before a date
Csh% when before 300 files older than an age
Csh% when after 3/25 or younger than a date this year
Csh% when before 2/1/94 and after 10/31/93 even a range
More options and clauses are supported. Look at the code for clues.
This one only works in the current directory. It also has an interesting
property. Maybe this is just ultrix, maybe not, I'd like to know anyway...
The interpreted version works fine, but the compiled version has a
numeric overflow. That'll make for some fun debugging. I wrote it for
myself as a tool to locate old files for archiving or deleting. Study and
enjoy!
Chris Tenaglia (System Manager) | "The past explained,
Medical College of Wisconsin | the future fortold,
8701 W. Watertown Plank Rd. | the present largely appologized for."
Milwaukee, WI 53226 | Organon to The Doctor
(414)257-8765 |
tenaglia@mis.mcw.edu
#
# file : when.icn
# desc : date based ls command for unix
# use : iconx when [to|before __] [from|since __] [asc | des] [long|brief] [do __]
# brief output pipable to rm and others
# long will include day age, but not protection mask
# spec : ls -al layout : month@33:3 day@37:2 yr@41:2|current
#
# update by what
# 06-apr-1994 tenaglia initial write
#
global base, # 1970 calculation baseline number
today, # displacement from 12:00:01am today
now, # upto the second mark for right now
method, # ascending or descending order
output, # long (ls -al) or brief (ls -1) style
command, # optional command to do on each file
files # list with files, sizes, and ages
procedure main(param)
calc_today()
files := directory()
method := "none"
output := "long"
command := ""
if *param = 0 then show_age()
every i := 1 to *param do
{
(option := param[i]) | break
case option of
{
"to" |
"before" |
"until" : {
files := before(files,param[i+1])
i +:= 1
}
"from" |
"since" |
"after" : {
files := since(files,param[i+1])
i +:= 1
}
"asc" : method:="ascending"
"des" : method:="descending"
"long" : output:="long"
"brief" : output:="brief"
"do" : {
every j := i+1 to *param do
command ||:= param[j] || " "
}
default : 5 # stop("Unrecognized option :",option)
}
}
show_age()
end
#
# just show another ls with days old numbers & optionally sorts
#
procedure show_age()
case method of
{
"none" : {
every line := !files do
{
age := (today - parse(line,' ')[1]) / 86400
ks := parse(line,' ')[2] / 1024
file:= line[23:0]
(command == "") |
{
write(command,line[37:0])
system(command || line[37:0])
next
}
if output == "brief" then text := line[37:0]
else text:= right(age,6) || " days " || right(ks,6) || " kb | " || file
write(text)
}
}
"descending" : {
results := sort(files)
every line := !results do
{
age := (today - parse(line,' ')[1]) / 86400
ks := parse(line,' ')[2] / 1024
file:= line[23:0]
(command == "") |
{
write(command,line[37:0])
system(command || line[37:0])
next
}
if output == "brief" then text := line[37:0]
else text:= right(age,6) || " days " || right(ks,6) || " kb | " || file
write(text)
}
}
"ascending" : {
results := sort(files)
every i := *results to 1 by -1 do
{
line:= results[i]
age := (today - parse(line,' ')[1]) / 86400
ks := parse(line,' ')[2] / 1024
file:= line[23:0]
(command == "") |
{
write(command,line[37:0])
system(command || line[37:0])
next
}
if output == "brief" then text := line[37:0]
else text:= right(age,6) || " days " || right(ks,6) || " kb | " || file
write(text)
}
}
default : 5
}
end
#
# remove elements later than a date
#
procedure before(lst,days)
static mtab
initial mtab := [0,31,59,90,120,151,181,212,243,273,304,334]
if find("/",days) then
{
mo := parse(days,'/')[1]
da := parse(days,'/')[2]
yr := parse(days,'/')[3] | parse(&date,'/')[1]
if yr < 100 then yr +:= 1900
tmp := yr * 31557600
dd := mtab[mo] + da
if ((yr % 4) = 0) & (mo > 2) then dd +:= 1
tmp+:= dd * 86400
age := tmp
} else {
age := now - (days * 86400)
}
work := []
every file := !lst do
{
old := parse(file,' ')[1]
if old <= age then put(work,file)
}
return copy(work)
end
#
# remove elements earlier than a date
#
procedure since(lst,days)
static mtab
initial mtab := [0,31,59,90,120,151,181,212,243,273,304,334]
if find("/",days) then
{
mo := parse(days,'/')[1]
da := parse(days,'/')[2]
yr := parse(days,'/')[3] | parse(&date,'/')[1]
if yr < 100 then yr +:= 1900
tmp := yr * 31557600
dd := mtab[mo] + da
if ((yr % 4) = 0) & (mo > 2) then dd +:= 1
tmp+:= dd * 86400
age := tmp
} else {
age := now - (days * 86400)
}
work := []
every file := !lst do
{
old := parse(file,' ')[1]
if old >= age then put(work,file)
}
return copy(work)
end
#
# calculate today and now figures
#
procedure calc_today()
static mtab
initial {
base := 1970*31557600
mtab := [0,31,59,90,120,151,181,212,243,273,304,334]
}
tmpy := parse(&date,'/')[1]
tmpm := parse(&date,'/')[2]
tmpd := parse(&date,'/')[3]
here := tmpy * 31557600 +
(mtab[tmpm] + tmpd) * 86400
if ((tmpy%4) = 0) & (tmpm > 2) then here +:= 86400
today := here
now := here +
parse(&clock,':')[1] * 3600 +
parse(&clock,':')[2] * 60 +
parse(&clock,':')[3]
end
#
# convert a ls -al output into a list for sorting and printing
#
procedure directory()
static mtab
initial {
mtab := table(0)
mtab["Jan"] := 0
mtab["Feb"] := 31
mtab["Mar"] := 59
mtab["Apr"] := 90
mtab["May"] := 120
mtab["Jun"] := 151
mtab["Jul"] := 181
mtab["Aug"] := 212
mtab["Sep"] := 243
mtab["Oct"] := 273
mtab["Nov"] := 304
mtab["Dec"] := 334
}
pipe := open("ls -al","pr")
entries := []
every line := !pipe do
{
if any('dclst',line) then next # ignore info and dirs
size := parse(line,' ')[4]
file := line[33:0]
day := mtab[parse(line,' ')[5]] + parse(line,' ')[6]
year := if line[40] == " " then parse(line,' ')[7] else parse(&date,'/')[1]
sec := if line[40] == " " then 0 else hhmm(parse(line,' ')[7])
mark := year * 31557600 + day * 86400 + sec
if (now-mark) < 0 then mark -:= 31557600
text := right(mark,12) || right(size,10) || " " || file
put(entries,text)
}
close(pipe)
return entries
end
#
# convert hh:mm into seconds since midnight
#
procedure hhmm(str)
hh := str[1+:2]
mm := str[4+:2]
return hh*3600 + mm*60
end
#
# parse a string into a list with respect to a delimiter
#
procedure parse(line,delims)
static chars
chars := &cset -- delims
tokens := []
line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
return tokens
end